package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.gourdplant.GourdPlantCombInfo;
import com.yanqu.road.entity.activity.gourdplant.GourdPlantConfig;
import com.yanqu.road.entity.activity.gourdplant.GourdPlantElement;
import com.yanqu.road.entity.activity.gourdplant.GourdPlantItemInfo;
import com.yanqu.road.pb.activity.GourdPlantProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;

public class GourdPlantPb {


    /**
     * 总配置
     */
    public static GourdPlantProto.GourdPlantConfigSyncMsg.Builder parseSyncConfigRespMsg(GourdPlantConfig config, String language) {
        GourdPlantProto.GourdPlantConfigSyncMsg.Builder builder = GourdPlantProto.GourdPlantConfigSyncMsg.newBuilder();
        for (GourdPlantCombInfo combInfo : config.getCombInfoList()) {
            builder.addComb(parseCombConfigTemp(combInfo, language));
        }
        for (GourdPlantItemInfo itemInfo : config.getItemInfoList()) {
            builder.addElement(parseGourdElementConfigTemp(itemInfo, language));
        }
        return builder;
    }

    /**
     * 组合配置
     */
    private static GourdPlantProto.GourdPlantCombConfigTemp.Builder parseCombConfigTemp(GourdPlantCombInfo combInfo, String language) {
        GourdPlantProto.GourdPlantCombConfigTemp.Builder builder = GourdPlantProto.GourdPlantCombConfigTemp.newBuilder();
        builder.setDesc(ServerLanguageMgr.getContent(combInfo.getDesc(), language));
        builder.setIcon(combInfo.getIcon());
        builder.setName(ServerLanguageMgr.getContent(combInfo.getName(), language));
        builder.setCombId(combInfo.getCombId());
        builder.setIntegral(combInfo.getIntegral());
        builder.setQuality(combInfo.getQuality());
        builder.setRewards(combInfo.getRewards());
        builder.setSort(combInfo.getSort());
        builder.setWeight(combInfo.getWeight());
        builder.addAllElement(combInfo.getElement());
        for (GourdPlantElement element : combInfo.getSpecialElement()) {
            GourdPlantProto.GourdPlantCombElementTemp.Builder elementBuilder = GourdPlantProto.GourdPlantCombElementTemp.newBuilder();
            elementBuilder.setItemId(element.getId());
            elementBuilder.setNum(element.getNum());
            builder.addSpecialElement(elementBuilder);
        }
        return builder;
    }

    /**
     *
     * 葫芦宝鉴
     */
    private static GourdPlantProto.GourdPlantElementConfigTemp.Builder parseGourdElementConfigTemp(GourdPlantItemInfo itemInfo, String language) {
        GourdPlantProto.GourdPlantElementConfigTemp.Builder builder = GourdPlantProto.GourdPlantElementConfigTemp.newBuilder();
        builder.setId(itemInfo.getId());
        builder.setIcon(itemInfo.getIcon());
        builder.setName(ServerLanguageMgr.getContent(itemInfo.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(itemInfo.getDesc(), language));
        return builder;
    }
}
